package dissertation.extensions.generate.resource.view;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.ui.DocumentAdapter;

import javax.swing.*;
import javax.swing.event.DocumentEvent;

public class CreateResourceDialogWrapper extends DialogWrapper {
    private CreateResourcePanel createResourcePanel;

    public CreateResourceDialogWrapper(Project project) {
        super(project);
        init();
        setResizable(false);
        setOKActionEnabled(false);
    }

    @Override
    protected JComponent createCenterPanel() {
        DocumentAdapter documentAdapter = new DocumentAdapter() {
            protected void textChanged(DocumentEvent e) {
                setOKActionEnabled(!createResourcePanel.getInputJTextField().getText().isEmpty());
            }
        };

        createResourcePanel = new CreateResourcePanel(documentAdapter);
        return createResourcePanel;
    }

    protected void doOKAction() {
        close(OK_EXIT_CODE);
    }

    public String getInput() {
        return createResourcePanel.getInputJTextField().getText();
    }
}
